//  Inside Microsoft Exchange 2007 Web Services 
//  Chapter 14
//
//  Copyright (c) 2007 David Sterling, Ben Spain, Mark Taylor, Huw Upshall, Michael Mainer.  
//  All rights reserved.
//
using System;
using System.Collections.Generic;
using System.Text;
using ProxyHelpers.EWS;

namespace AndWithMultipleChildrenUsingExtensions.cs
{
    class Program
    {
        static void Main(string[] args)
        {
            // Listing 14-9
            // first child of And --> Not(IsGreaterThan(itemSize, 100000))
            //
            NotType not = new NotType();

            // build up our IsGreaterThan leaf filter
            //
            IsGreaterThanType greaterThan =
              TwoOperandExpressionType.CreateConstantComparison<IsGreaterThanType>(
                        new PathToUnindexedFieldType(
                              UnindexedFieldURIType.itemSize),
                              "100000");

            not.Item = greaterThan;

            // second child of And --> IsLessThan(datesent, 2006-11-03T12:00:00Z)
            // 
            IsLessThanType lessThan =
              TwoOperandExpressionType.CreateConstantComparison<IsLessThanType>(
                   new PathToUnindexedFieldType(
                           UnindexedFieldURIType.itemDateTimeSent),
                           "2006-11-03T12:00:00Z");

            // last child of And --> IsEqualTo(itemClass, "IPM.Note")
            //
            IsEqualToType isEqualTo =
               TwoOperandExpressionType.CreateConstantComparison<IsEqualToType>(
                           new PathToUnindexedFieldType(
                                  UnindexedFieldURIType.itemItemClass),
                                  "IPM.Note");

            // now, create our and.  It has three child filters
            //
            AndType and = new AndType();
            and.Items = new SearchExpressionType[] { 
                 greaterThan, lessThan, isEqualTo };

            RestrictionType restriction = new RestrictionType();
            // Set our Not instance to be the filter associated with our restriction 
            // element
            restriction.Item = and;

        }
    }
}
